View Issue Details

IDProjectCategoryView StatusLast Update
0001749K18X001.00 SKB SWANSWpublic2023-06-22 10:25
Reporter(ALTech) Sangmin Choi Assigned To(SW) Jason LingDue Date
PrioritynormalSeveritys4-minorReproducibilityN/A
Status closedResolutionfixed 
Summary0001749: Please apply this patch from CSMSKBSBLT-214.
DescriptionHello, Jason,

When I run the monkey aging test, there is an issue that the ampservice has crashed.
Synaptics released patch and I ran the monkey aging test several times and I think this issue was fixed.

Please apply this patch from CSMSKBSBLT-214.

syna-release/ampsdk
0001-AMP-event-add-mutex-for-rwlock-to-avoid-it-dead-lock.patch

Thank you.
Sangmin Choi.
TagsNo tags attached.
Attach Tags

Users monitoring this issue

User List There are no users monitoring this issue.

Activities

(ALTech) Sangmin Choi

2023-06-22 09:10

developer  

0001-AMP-event-add-mutex-for-rwlock-to-avoid-it-dead-lock.patch (4,762 bytes)   
From 3fbf857a07b630c7881bacdb4ec2b853bbbbaf37 Mon Sep 17 00:00:00 2001
From: Zhiliang Wang <Zhiliang.Wang@synaptics.com>
Date: Wed, 5 Jan 2022 11:14:29 +0800
Subject: [PATCH] AMP: event: add mutex for rwlock to avoid it dead lock

currently there is bug in pthread lib, dead lock will easily
occur when multiple threads call pthread_rwlock apis, add
mutext as a workaround to avoid it

Change-Id: Ie0ecf17cb27d00c5c9119ab9fdd52cc3319a8543
---
 amp/src/libs/server/amp_event_service.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/amp/src/libs/server/amp_event_service.c b/amp/src/libs/server/amp_event_service.c
index 623866b..30644dd 100755
--- a/amp/src/libs/server/amp_event_service.c
+++ b/amp/src/libs/server/amp_event_service.c
@@ -97,6 +97,7 @@ typedef struct {
 #ifdef AMP_LATENCY_EVENT_SRV_PROF
     AMP_TOP                         stEventCBStats;
 #endif
+    MV_OSAL_HANDLE_MUTEX_t          hMutex;
 } EVENT_LISTEN_SERVICE;
 
 static EVENT_LISTEN_SERVICE         *m_event_service;
@@ -292,10 +293,12 @@ HRESULT ISL_Listener_Create(UINT uiSrvIdN, UINT uiSrvIdC, HANDLE *phListener)
     EVENT_LISTEN_SERVICE *pEventService = m_event_service;
     EVENT_LISTEN_CLIENT *pClientListener = NULL;
 
+    MV_OSAL_Mutex_Lock(pEventService->hMutex);
     MV_OSAL_RWLock_WRLock(pEventService->hEventLock);
     pClientListener = alloc_event_listener(pEventService);
     if (!pClientListener) {
         MV_OSAL_RWLock_Unlock(pEventService->hEventLock);
+        MV_OSAL_Mutex_Unlock(pEventService->hMutex);
         AMPLOGE("Allocate listen fail!(%x %x)", uiSrvIdN, uiSrvIdC);
         return HRESULT_GEN(EVENTLI, ERR_NOSWRSC);
     }
@@ -305,11 +308,13 @@ HRESULT ISL_Listener_Create(UINT uiSrvIdN, UINT uiSrvIdC, HANDLE *phListener)
     if (rc != SUCCESS) {
         pClientListener->bAllocated = 0;
         MV_OSAL_RWLock_Unlock(pEventService->hEventLock);
+        MV_OSAL_Mutex_Unlock(pEventService->hMutex);
         AMPLOGE("%p new eventbuf (%x %x) rc:%x", pClientListener, uiSrvIdN, uiSrvIdC, rc);
         return rc;
     }
 
     MV_OSAL_RWLock_Unlock(pEventService->hEventLock);
+    MV_OSAL_Mutex_Unlock(pEventService->hMutex);
     AMPLOGD("%p new eventsrv (%x %x) rc:%x", pClientListener, uiSrvIdN, uiSrvIdC, rc);
     *phListener = (HANDLE) pClientListener;
 
@@ -333,6 +338,7 @@ HRESULT ISL_Listener_Destory(HANDLE hListener)
     AMP_RemoteEventCallbackPro((UINT32)pClientListener, &event);
     AMPLOGD("NOTIFY listener:%x, we are done", pClientListener);
 
+    MV_OSAL_Mutex_Lock(pEventService->hMutex);
     MV_OSAL_RWLock_WRLock(pEventService->hEventLock);
     rc = AMP_DeinitEventBuffer(&pClientListener->hEventBuffer);
     if (rc != S_OK) {
@@ -341,6 +347,7 @@ HRESULT ISL_Listener_Destory(HANDLE hListener)
     pClientListener->bAllocated = 0;
     pEventService->uiAllocatedClients--;
     MV_OSAL_RWLock_Unlock(pEventService->hEventLock);
+    MV_OSAL_Mutex_Unlock(pEventService->hMutex);
 
     return SUCCESS;
 }
@@ -496,13 +503,20 @@ HRESULT AMP_InitializeRemoteEventService()
     }
     AmpMemSet(pEventService, 0, sizeof(EVENT_LISTEN_SERVICE));
 
-    rc = MV_OSAL_RWLock_Create(&pEventService->hEventLock);
+    rc = MV_OSAL_Mutex_Create(&pEventService->hMutex);
     if (rc != S_OK) {
         AMPLOGE("Create mutex fail:%x\n", rc);
         AmpFree(pEventService);
         return rc;
     }
 
+    rc = MV_OSAL_RWLock_Create(&pEventService->hEventLock);
+    if (rc != S_OK) {
+        AMPLOGE("Create RWLock fail:%x\n", rc);
+        AmpFree(pEventService);
+        return rc;
+    }
+
     evl_cache_add_event(&pEventService->stEventCache, AMP_EVENT_API_DISP_CALLBACK_VSYNC);
 
     m_event_service = pEventService;
@@ -519,6 +533,10 @@ HRESULT AMP_DeinitializeRemoteEventService()
     if (rc != S_OK) {
         return rc;
     }
+    rc = MV_OSAL_Mutex_Destroy(&pEventService->hMutex);
+    if (rc != S_OK) {
+        return rc;
+    }
     if (pEventService) {
         AmpFree(pEventService);
         m_event_service = NULL;
@@ -555,11 +573,14 @@ HRESULT AMP_RemoteEventCallbackPro(UINT32 ServiceID, AMP_EVENT *pEvent)
         return SUCCESS;
     }
 
+    MV_OSAL_Mutex_Lock(pEventService->hMutex);
+
     ll = send = 0;
     if (ServiceID == REMOTE_EVENT_SERVERID_DEFAULT) {
         rc = MV_OSAL_RWLock_TryWRLock(pEventService->hEventLock, 10);
         if (rc != S_OK) {
             AMPLOGE("trylock eventlock rc:%x", rc);
+            MV_OSAL_Mutex_Unlock(pEventService->hMutex);
             return rc;
         }
 
@@ -605,6 +626,7 @@ HRESULT AMP_RemoteEventCallbackPro(UINT32 ServiceID, AMP_EVENT *pEvent)
     }
 
     MV_OSAL_RWLock_Unlock(pEventService->hEventLock);
+    MV_OSAL_Mutex_Unlock(pEventService->hMutex);
 
     return rc;
 }
-- 
2.7.4

(SW) Jason Ling

2023-06-22 10:18

developer   ~0013481

Hi Sangmin,

Done

2023-06-22 10:17:55 | Zhiliang.Wang@syna.. | 30a4991c | syna-release/ampsdk | AMP: event: add mutex for rwlock to avoid it dead lock

Thanks,
Jason

(ALTech) Sangmin Choi

2023-06-22 10:25

developer   ~0013482

Hello, Jason,

Thank you always!

Issue History

Date Modified Username Field Change
2023-06-22 09:10 (ALTech) Sangmin Choi New Issue
2023-06-22 09:10 (ALTech) Sangmin Choi Status new => assigned
2023-06-22 09:10 (ALTech) Sangmin Choi Assigned To => (SW) Jason Ling
2023-06-22 09:10 (ALTech) Sangmin Choi File Added: 0001-AMP-event-add-mutex-for-rwlock-to-avoid-it-dead-lock.patch
2023-06-22 10:18 (SW) Jason Ling Status assigned => resolved
2023-06-22 10:18 (SW) Jason Ling Resolution open => fixed
2023-06-22 10:18 (SW) Jason Ling Note Added: 0013481
2023-06-22 10:25 (ALTech) Sangmin Choi Status resolved => closed
2023-06-22 10:25 (ALTech) Sangmin Choi Note Added: 0013482